package com.cs.paoyer.common;



import java.sql.Connection;
import java.sql.SQLException;

//import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource ;

/**
 * Fabrica que permite localizar las conexiones JDBC a la base de datos.
 * ORACLE_9IAS_HOME\j2ee\home\config\data-sources.xml
 *
  <data-source class="com.evermind.sql.DriverManagerDataSource"
		location="CSDataSource"
		password="tiger"
		min-connections="5"
		username="scott"
		url="jdbc:oracle:thin:@localhost:1521:orcl"
		xa-location="CSDataSourceXA"
		connection-driver="oracle.jdbc.OracleDriver"
		wait-timeout="30"
		max-connections="10"
		name="CSDataSource"
		ejb-location="CSDataSource"/>
 *
 *
 * @version 1.0
 */
public class DataSourceFactory {
  //Produccion
  public static final String JDNI_DATASOURCE = "jdbc/CSDataSource";
  //Desarrollo
  //private static final String JDNI_DATASOURCE = "jdbc/CSDataSourceDS";
  
  /**
   * Obtiene una conexion JDBC del DataSource.
   *
   * @return conexion JDBC del DataSource.
   * @throws NamingException  Cuando existe un problema al intentar 
   * localizar el data source.
   * @throws SQLException  Cuando existe un problema al intentar comunicaci�n
   * con la fuente de datos.
   */
  public static Connection getConnection() throws SQLException, NamingException {
    
    InitialContext initctx = new InitialContext();
    DataSource ds = (DataSource)initctx.lookup(JDNI_DATASOURCE);
    /*conn = ds.getConnection();
    Context context = new  InitialContext();
    DataSource dataSource = (DataSource) context.lookup( CS_DATA_SOURCE  );
    Connection connection = dataSource.getConnection();*/
    Connection connection = ds.getConnection();
    return connection;
//      Context context = new  InitialContext();
//      DataSource dataSource = (DataSource) context.lookup("jdbc/PaoyerMunMedCoreDS");
//      Connection connection = dataSource.getConnection();
//      return connection;

  }
  

}